/* 
 * Copyright (C) 2006 Sasa Coh <sasacoh@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */

using System.Collections.Generic;

namespace MenuDesigner 
{
  /***************************************************************
  * @struct TCharMap
  *
  * @brief Character mapping structure
  *
  * @author Sasa Coh
  */
  public struct TCharMap {
    public TCharMap(char ch, string str1, string str2) 
    {
      numeric_char = ch;
      lower_chars = str1;
      upper_chars = str2;
    }

	  public char numeric_char;
    public string upper_chars;
    public string lower_chars;
  } 


  /***************************************************************
  * @class CLanguage
  *
  * @brief Language class
  *
  * @author Sasa Coh
  */
  public class CLanguage
  {
    protected List<TCharMap> _keymap;

    protected Dictionary<string, string> _langTable;

    protected CLanguage()
    {
      _keymap = new List<TCharMap>(12);
      _langTable = new Dictionary<string, string>();
    }

    public void setDefaultKeyMapping()
    {
      _keymap.Add (new TCharMap('0', " 0",								" 0"));
			_keymap.Add (new TCharMap('1', ".,\'?!\"-:#*=<>1",  ".,\'?!\"-:#*=<>1"));
      _keymap.Add (new TCharMap('2', "abc2",							"ABC2"));
			_keymap.Add (new TCharMap('3', "def3",							"DEF3"));
      _keymap.Add (new TCharMap('4', "ghi4",							"GHI4"));
      _keymap.Add (new TCharMap('5', "jkl5",							"JKL5"));
      _keymap.Add (new TCharMap('6', "mno6",							"MNO6"));
      _keymap.Add (new TCharMap('7', "pqrs7",							"PQRS7"));
      _keymap.Add (new TCharMap('8', "tuv8",							"TUV8"));
      _keymap.Add (new TCharMap('9', "wxyz9",							"WXYZ9"));
      _keymap.Add (new TCharMap('*', "*",									"*"));
      _keymap.Add (new TCharMap( '#', "#", "#" )); 
    }


    public virtual string getItem(string item)
    {
      if (_langTable.ContainsKey(item.ToLower()))
      {
        return _langTable[item.ToLower()];
      }
      return item;
    }

    public char getCharacter(int id, int count, EEditMode mode)
    {
      char result = ' '; 
      if (_keymap.Count == 0) return ' ';
      switch (mode)
      {
        case EEditMode.numeric: result = _keymap[(int)id].numeric_char; break;
        case EEditMode.alphanum_high: result = _keymap[(int)id].upper_chars[(int)count % _keymap[(int)id].upper_chars.Length]; break;
        case EEditMode.alphanum_low: result = _keymap[(int)id].lower_chars[(int)count % _keymap[(int)id].lower_chars.Length]; break;
      }
      return result;
    }

  }

} //namespace MenuDesigner